// var newsList = [{
// 	title:"新闻",
// 	from:"北京出版设",
// 	date:"10:09 12:30",
// 	imgs:["D:\HTML5文件\baidu\yyy.jpg"]
// },{
// 	title:"新闻",
// 	from:"北京出版设",
// 	date:"10:09 12:30",
// 	imgs:["D:\HTML5文件\baidu\yyy.jpg",
// 	"D:\HTML5文件\baidu\yyy.jpg",
// 	"D:\HTML5文件\baidu\yyy.jpg"
// 	]
// }];
function newsElementAppendTo(parent,tagname,classname){
		//生成新的元素
		var ele = document.createElement(tagname);
		
		//在父元素中，追加新元素
		parent.appendChild(ele);
		//修改新的元素class
		ele.className =  classname;
		//返回新的元素的js操作对象
		//ele.innerText = newsList[0].title;
		return ele;
		}	




function addNewsItem(newsObj){
//获取父元素得js操作对象
var news = document.querySelector("#news");
//给新元素添加class news-item
var newsItem = newsElementAppendTo(news,"div","news-item");
//给新元素添加class news-item
if(newsObj.imgs.length ==1){
	newsItem.className = "news-item single";
}
var newsTitle = newsElementAppendTo(newsItem,"div","news-title")
var newsImgs = newsElementAppendTo(newsItem,"div","news-imgs")
var newsInfo = newsElementAppendTo(newsItem,"div","news-info")
newsTitle.innerText = newsObj.title;
for(i in newsObj.imgs){
	src = newsObj.imgs[i];
	img = newsElementAppendTo(newsImgs,"img","");
	img.src=src;
}
newsInfo.innerHTML += '<span class="news-from">' + newsObj.from+ '</span>';
newsInfo.innerHTML += '<span class="news-time">' + newsObj.date+ '</span>';
}
//创建XMLHttpRequest对象
var xhr = new XMLHttpRequest();
//打开XMLHttpRequest对象
xhr.open("get","http://127.0.0.1:8848/HTML5%E6%96%87%E4%BB%B6/baidu/baidu.json",true);
//发送http请求
xhr.send(null);

//读取响应数据
//var newsList = JSON.parse(xhr.responseText);//接受数据

xhr.onreadystatechange = function(){
	//判断请求是否成功
	if(xhr.readyState == 4){
		//判断http状态码请求是否成功
		if(xhr.status == 200){
			var newsList = JSON.parse(xhr.responseText);
			for(i in newsList){
			 	addNewsItem(newsList[i]);
			 }
		}
	}
	console.log(xhr.responseText);
}
// for(i in newsList){
// 	addNewsItem(newsList[i]);
// }

// for(i in newsObj.imgs){
// 		src=newsObj.imgs[i];
// 		img = newsElementAppendTo(newsImgs,"img","");
// 		img.src = src;
// 		}
 // 4.给news -title添加内容, innerHTML, innerText, textContent
 //newsTitle.innerText = newsList[0].title;
 // 5. 给news - imgs添加img
// for(i in newsList[0].imgs){
// 	src=newsList[0].imgs[i];
// 	img = newsElementAppendTo(newsImgs,"img","");
// 	img.src = src;
// }
window.onscroll = function(){
	//水平方向的公董距离是scrollX,垂值方向的工地距离是scrollY
	console.log(window.scrollY);
	var logoFixed = document.querySelector('.logo-fixed');
	if(window.scrollY >= 210){
		logoFixed.className = "logo-fixed show";
	}else{
		logoFixed.className= "logo-fixed";
	}
}


















 // 6.给news - info添加内容
 //newsInfo.innerHTML += '<span class="news-from">' + newsList[0].from+ '</span>';
 //newsInfo.innerHTML += '<span class="news-time">' + newsList[0].date+ '</span>';
//1.createElement方法是js动态创建HTML元素得方法,把要创建得元素
//给新元素添加class news-item
// var newsItem = document.createElement("div");
// var newsTitle = document.createElement("div");
// var newsInfo = document.createElement("div");
// var newsImgs = document.createElement("div");
// //2.指定父元素，新元素追加到该元素得子元素最后面

// news.appendChild(newsItem);
// newsItem.appendChild(newsTitle);
// newsItem.appendChild(newsImgs);
// newsItem.appendChild(newsInfo);
// //给新元素添加class news-item
// newsItem.className = "news-item single";
// newsTitle.className = "news-title";
// newsImgs.className = "news-imgs";
// newsInfo.className = "news-info";